﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace EzDesk.Attendance.MobileWeb.Controllers.Attendance
{
    public class AttendanceRoleAuthorizeActionFilterAttribute : ActionFilterAttribute
    {
        public string AttendanceRoles
        {
            get;
            set;
        }

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var coltroller = (filterContext.Controller as AttendanceController);
            if (coltroller != null && AttendanceRoles != null)
            {
                var roles = coltroller.CurrentRoles;
                foreach (var role in roles)
                {
                    if (AttendanceRoles.Contains(role.ToString()))
                    {
                        base.OnActionExecuting(filterContext);
                        return;
                    }
                }                
            }
            //todo: 跳转到错误页面
            throw new Exception("权限错误");
        }
    }
}
